package com.hst.web.base.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.hst.core.dao.IORDao;
import com.hst.core.dao.ORQuery;
import com.hst.core.dao.ORQuery.Op;
import com.hst.core.json.JsonUtil;
import com.hst.web.base.entity.TReivewHistory;

@Controller
@RequestMapping("/review")
public class ReviewController {

	@Autowired
	IORDao dao;

	@SuppressWarnings("unchecked")
	@RequestMapping("/history")
	public void history(@RequestBody String param, Model m)
			throws JsonParseException, JsonMappingException, IOException {
		Map<String, Object> data = JsonUtil.read(param, Map.class);
		List<ORQuery> querys = new ArrayList<ORQuery>();
		String employeeCode = (String) data.get("employeeCode");
		String vehicleCode = (String) data.get("vehicleCode");
		
		if (employeeCode != null) {
			querys.add(new ORQuery(Op.eq, "employeeCode", employeeCode));
		}
		if (vehicleCode != null) {
			querys.add(new ORQuery(Op.eq, "vehicleCode", vehicleCode));
		}
		querys.add(new ORQuery(Op.order, "createTime", "desc"));
		m.addAttribute("data", dao.list(TReivewHistory.class, querys));
	}

}
